<template>
<Modal
	v-model="show"
	title="添加权限组"
	:width="640"
	>
	<Form :model="info" :label-width="150" style="width: 100%" :rules="ruleValidate" ref="form">
		
		<Row>
			<Col>
				<FormItem label="权限组名称：" prop="name">
					<Input v-model="info.name" placeholder="" style="width: 300px;"></Input>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="职能描述：">
					<Input type="textarea" v-model="info.info" placeholder="" :rows="4" style="width: 300px;"></Input>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="添加组员：" prop="ids">
					<user_filter v-model="info.ids" style="width: 300px;" ></user_filter>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="是否启用：">
					 <i-switch v-model="info.is_enable" :true-value="1" :false-value="0" size="large"></i-switch>
				</FormItem>
			</Col>
		</Row>
		
	</Form>

	<div slot="footer" style="text-align: center;">
		<Button type="success" size="large" @click="handleSubmit('form')">提交</Button>
	</div>
</Modal>
</template>

<script>
import user_filter from '@/themes/components/user_filter_more';

export default {
	name: 'bumen_info',
	components:{
		user_filter
	},
	data(){
		return {
			show:false,
			def_info:{
				name:'',
				info:'',
				ids:'',
				is_enable:1,
				id:0
			},
			info:{
				name:'',
				info:'',
				ids:'',
				is_enable:1,
				id:0
			},
			ruleValidate:{
				name:[
					{ required: true, message: '请填写部门名称', trigger: 'blur' }
				],
				/*
				ids:[
					{ required: true, message: '请添加组员', trigger: 'blur' }
				],
				*/
			},
		};
	},
	props:['value','cinfo'],
	created(){
		this.show = this.value;
		
	},
	watch:{
		value(val){
			this.show = val;
		},
		show(val){
			this.$emit('input',val);
		},
		cinfo:{
			handler(val){
				if(typeof(val)!='object'){
					this.info = this._getData(this.def_info);
					return;
				}
				for(var i in this.info){
					if(typeof(val[i])!='undefined'){
						this.info[i] = val[i];
					}
					else{
						this.info[i] = this.def_info[i];
					}
				}
				this.info.is_enable = parseInt(this.info.is_enable);
				
				if(this.info.ids){
					this.info.ids = this.info.ids.split(',');
				}
			},
			deep:true
		}
	},
	methods: {
		 handleSubmit(name) {
			var self = this;
			this.$refs[name].validate((valid) => {
				if(valid) {
					self.save();
				}
			})
		},
		save(){
			var self = this;
			
			var postdata = this.info;
			
			
			Whttp.load('System/Privgroup/save',postdata,function(res){
				self.$Message.info('提交成功');
				self.$emit('success',res);
				self.show = false;
			});
		}
	}
}
</script>
<style scoped>

</style>